/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oraclefmw.weibo;

import java.util.ArrayList;
import java.util.List;
import weibo4j.*;

import java.sql.*;


/**
 *
 * @author gniu
 */
public class WeiboGeneric {
    
    public static final int FOLLOWER = 2;
    public static final int FRIEND = 1;
    
    private  Weibo weibo;
     
    public Weibo getWeibo() {
        
        if ( weibo == null ) {
            
            System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
            System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
            weibo = new Weibo();
            weibo.setToken( "32bcaf55eeba6a3d66dbd2ecc3e2170f","aa37cb93adba295790372a64ae799d93");
        }
        
        return weibo;
    }

   
    
    public List getUsers( int type ) throws WeiboException {
        
        
        List<User> users = new ArrayList<User>();
      
        List<User> tempUsers = new ArrayList<User>();

        int curPage = -1;
        int cursor = -1;
        
        do {
            
            if ( type == FRIEND ) 
                tempUsers = getWeibo().getFriendsStatuses(cursor);
            else
                 tempUsers = getWeibo().getFollowersStatuses(cursor);
            
            users.addAll(tempUsers);

            if (curPage == -1) {
                curPage = 1;
                cursor = 1;
            } else {
                curPage++;
            }

            cursor = 20 * curPage;
        
        } while (tempUsers.size() > 0);
        
       return users;
    }
    
  
}
